home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17557 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  55 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: Pure virtual destructors?
  5. Message-ID: <marnoldDpxy4K.1wv@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <4kuq0i$p6t@ftp.ee.vill.edu> <marnoldDpxt3n.F12@netcom.com>
  8. Date: Tue, 16 Apr 1996 06:02:44 GMT
  9. Sender: marnold@netcom19.netcom.com
  10.  
  11. marnold@netcom.com (Matt Arnold) writes:
  12.  
  13. >sheridan@monet.vill.edu writes:
  14.  
  15.  
  16. >>The rule with destructors is that they are always overridden, right?
  17. >>That's a quote from VC4 docs, BTW.  When I do this:
  18.  
  19. >>class CBase {
  20. >>public:
  21. >>    virtual ~CBase() = 0;
  22. >>...};
  23.  
  24. >>class CChild : public CBase {
  25. >>public:
  26. >>    ~CChild();
  27. >>...};
  28.  
  29. >>and declare a body for ~CChild, I always get unresolved external on
  30. >>CBase::~CBase.  I have seen this in several cases.  My guess is it's not
  31. >>a compiler bug, so what am I missing?
  32.  
  33. >You're missing the fact that virtual destructors are *always* called, 
  34. >even pure ones (in your example, before ~CChild is executed, ~CBase
  35.  
  36. Whoa!  I said that backwards!!!  The "Reverse" key on my terminal 
  37. must have been stuck down.
  38.  
  39. That above should have been "~CBase will always be executed before 
  40. ~CChild executes, no matter what".  Since, of course, objects in
  41. C++ are always destroyed in exactly the opposite order of their
  42. construction.  Sorry for any confusion.
  43.  
  44. >*will* be executed no matter what).  You get link errors because the
  45. >compiler is looking for the CBase::~CBase() you forgot to define.
  46.  
  47.  
  48. -------------------------------------------------------------------------
  49. Matt Arnold                       |        | ||| | |||| |  | | || ||
  50. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  51. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  52. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  53. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  54. -------------------------------------------------------------------------
  55.